%==========================================================================
% List of the files on which this procedure depends:
%
% getFileSequenceFromRepresetative.m
%
%==========================================================================
function testRename(inFileName, firstFileInd, lastFileInd)
% testRename('C:\E\Scratch\NEH129_ProRes\NEH129_ProResN_N_N_000001.pgm', 1, 100);

[inDirPath, inFileNamePrefixNoPath, indFieldLength, inFileExt, fileIndArr] = ...
    getFileSequenceFromRepresetative(inFileName, firstFileInd, lastFileInd);
firstFileInd = fileIndArr(1);
lastFileInd = fileIndArr(end);


inFileNamePrefix = [inDirPath, inFileNamePrefixNoPath];
outFileNamePrefix = [inFileNamePrefix 'N_'];
timeArr = zeros(3, 1);


t1 = tic;
for k = firstFileInd:lastFileInd
    inFileName = [inFileNamePrefix num2str(k, ['%0' num2str(indFieldLength) 'd']) '.' inFileExt];
    outFileName = [outFileNamePrefix num2str(k, ['%0' num2str(indFieldLength) 'd']) '.' inFileExt];
    java.io.File(inFileName).renameTo(java.io.File(outFileName));
end
timeArr(1) = toc(t1);


inFileNamePrefix = outFileNamePrefix;
outFileNamePrefix = [inFileNamePrefix 'N_'];


t1 = tic;
for k = firstFileInd:lastFileInd
    inFileName = [inFileNamePrefix num2str(k, ['%0' num2str(indFieldLength) 'd']) '.' inFileExt];
    outFileName = [outFileNamePrefix num2str(k, ['%0' num2str(indFieldLength) 'd']) '.' inFileExt];
    movefile(inFileName, outFileName);
end
timeArr(2) = toc(t1);



inFileNamePrefix = outFileNamePrefix;
outFileNamePrefix = inFileNamePrefixNoPath;

t1 = tic;
for k = firstFileInd:lastFileInd
    inFileName = [inFileNamePrefix num2str(k, ['%0' num2str(indFieldLength) 'd']) '.' inFileExt];
    outFileName = [outFileNamePrefix num2str(k, ['%0' num2str(indFieldLength) 'd']) '.' inFileExt];
    system(['mv "' inFileName '" "' outFileName '"']);
end
timeArr(3) = toc(t1);

fprintf(1, 'Java time = %f \n', timeArr(1));
fprintf(1, 'movefile time = %f \n', timeArr(2));
fprintf(1, '!mv time = %f \n', timeArr(3));

return;
% end of the function "testRename"
